/*
  学习目标：封装Action创建函数, 替代字面量action写法
 
*/

import { legacy_createStore as createStore } from 'redux';

// 1. 封装Action创建函数
export function addAction(num) {
  return {
    type: 'add',
    payload: num,
  };
}

export const desAction = (num) => {
  return {
    type: 'des',
    payload: num,
  };
};

const initState = {
  count: 99,
  msg: '',
  title: '',
  name: 'zs',
};

function countReducer(state = initState, action) {
  console.log('action  ----->  ', action);

  switch (action.type) {
    case 'add':
      return { count: state.count + action.payload };

    case 'des':
      return { count: state.count - action.payload };
    default:
      return state;
  }
}

const store = createStore(countReducer);

export default store;
